#include "Syntax/Tree.hpp"
#include "Syntax/Parser.hpp"
#include "Syntax/LexicalScanner.hpp"

#include "Text/SourceText.hpp"

SyntaxTree::SyntaxTree(SourceText &text) : Text(text)
{
  SyntaxParser Parser(text);
  this->Root = Parser.ParseCompilationUnit();
  this->Diagnostics = Parser.Diagnostics();
}

SharedTree SyntaxTree::Parse(std::string &text)
{
  auto sourceText = SourceText::From(text);
  return Parse(sourceText);
}

SharedTree SyntaxTree::Parse(SourceText &text)
{
  return std::make_shared<SyntaxTree>(text);
}

SharedToken SyntaxTree::ParseTokens(std::string &text)
{
  auto sourceText = SourceText::From(text);
  return ParseTokens(sourceText);
}
SharedToken SyntaxTree::ParseTokens(SourceText &text)
{
  LexicalScanner lexer(text);
  while (true)
  {
    auto token = lexer.NextToken();
    if (token->GetKind() == SyntaxKind::Eof)
      break;

    return token;
  }
  return nullptr;
}